/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.tabbedproperties.section;


import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.IUMLElementEditPart;
import com.cea.papyrus.core.profiles.ProfileComposite;
import com.cea.papyrus.core.tabbedproperties.PropertyViewSection;


/**
 * 
 */
public class ProfileSection extends PropertyViewSection {

	/**
	 * 
	 */
	private ProfileComposite profileComposite;
	
	/**
	 * 
	 */
	private ModelManager modelManager;

	/**
	 * 
	 * 
	 * @param tabbedPropertySheetPage 
	 * @param parent 
	 */
	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage tabbedPropertySheetPage) {
		super.createControls(parent, tabbedPropertySheetPage);
		profileComposite = new ProfileComposite(parent, getWidgetFactory());
		profileComposite.createContent();
	}
	
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public boolean shouldUseExtraSpace() { 
		return true; 
	}

	/**
	 * 
	 */
	@Override
	public void refresh() {
		profileComposite.refresh();
	}

	/**
	 * 
	 * 
	 * @param part 
	 * @param selection 
	 */
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
		super.setInput(part, selection);
		Assert.isTrue(selection instanceof IStructuredSelection);
		Object input = ((IStructuredSelection) selection).getFirstElement();
		if(input instanceof IUMLElementEditPart) {
			this.modelManager = ((IUMLElementEditPart) input).getModelManager();
			profileComposite.setSelection(selection);
			profileComposite.setModelManager(this.modelManager);
		}
	}
	
	/**
	 * 
	 */
	public void dispose(){
		super.dispose();
		if(profileComposite!=null)
			profileComposite.disposeListeners();
	}
}
